import { PixijsRender } from "../PixijsRender";
import { BaseEntity } from "./BaseEntity";

import { ViewState } from "./PixijsEntities";
import { GroupEntity } from "./GroupEntity";

export class DynamicEntity extends GroupEntity   {

    constructor(pixiRender: PixijsRender) {
        super(pixiRender);
        this.name = 'dynamic';
        this.className = this.constructor.name
  
    }

    setValue(nodepath: string, attribute: string, value: any) {
        let nodes = nodepath.split('/');
        let node = this.view;
        for (let i = 0; i < nodes.length; i++) {
            const name = nodes[i];
            if(node) {
                node = node.getChildByName(name);
            }
            else {
                return;
            }
        }

        if(node) {
            if(attribute === 'url') {
                this.__render.world.update<BaseEntity>(node as any as BaseEntity, 'viewState', ViewState.WaitLoad);  
            }
            this.__render.world.update<BaseEntity>(node as any as BaseEntity, attribute as any, value);  
        }
    }
}